import requests
import json
import turtle as t

def get_data():
    url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_other&callback=jQuery34109115895667113716_1582869774819&_=1582869774820'
    headers = {'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36'}
    res = requests.get(url, headers=headers).text
    #res = requests.get(url).text
    a = res.split("jQuery34109115895667113716_1582869774819(")
    b=a[1]
    d=b[0:-1]
    c = json.loads(d)
    data = json.loads(c['data'])
    return data
datas = get_data()
print(datas)
'''
datas = get_data()["dailyNewAddHistory"]
lists1=[]
lists2=[]
lists3=[]
for data in datas:
    lists1.append(data["country"])
    lists2.append(data["hubei"])
    lists3.append(data["notHubei"])

global date

date = int(len(lists1))
t.ht()
t.setup(900,680)
t.penup()
t.goto(-400,-300)
t.pendown()
for i in range(date+1):
    t.dot(5,"black")
    t.forward(800/(date+1))
    
t.write("日期",font=10)
t.left(144)
t.forward(8)
t.backward(8)
t.left(72)
t.forward(8)
t.backward(8)
t.penup()
t.goto(-400,-300)
t.pendown()
t.right(126)
t.forward(600)
t.write("人数",font=10)
t.left(144)
t.forward(8)
t.backward(8)
t.left(72)
t.forward(8)
t.backward(8)


def draw_add_picture(new_lists,color):
    t.penup()
    t.goto(-400+800/(date+1),new_lists[0]*0.0375-300)
    t.pendown()
    t.pencolor(color)
    n=1
    for new_list in new_lists:
        t.goto(-400+(800/(date+1))*n,new_list*0.0375-300)
        t.dot(5,color)
        t.write(str(new_list))
        n+=1
draw_add_picture(lists1,"black")
draw_add_picture(lists2,"brown")
draw_add_picture(lists3,"green")
'''

'''
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from urllib.request import urlopen
from bs4 import BeautifulSoup
import time

browser = webdriver.Firefox()
url= "https://voice.baidu.com/act/newpneumonia/newpneumonia/?from=osari_pc_3"
browser.get(url)
time.sleep(1)
# 将滚动条下拉至最低
target1 = browser.find_elements(By.CLASS_NAME,"VirusTrend_1-1-192_1U4OF0")
target2 = target1[1]
browser.execute_script("arguments[0].scrollIntoView();", target2)
ActionChains(browser).move_by_offset(330,300).perform()
html = urlopen(url).read().decode("utf-8")
'''
